package org.streets.workflow.engine.task;

import org.streets.workflow.engine.ITaskInstance;
import org.streets.workflow.engine.IWorkItem;
import org.streets.workflow.engine.WorkflowEngine;
import org.streets.workflow.engine.WorkflowException;
import org.streets.workflow.engine.event.TaskEvent;


public class DefaultTaskEventListener implements	ITaskEventListener {


	public void onTaskEventFired(WorkflowEngine engine, TaskEvent event) throws WorkflowException {

		ITaskInstance task = event.getSource();
		IWorkItem workitem = event.getWorkItem();
		
		if (event.getEventType()==TaskEvent.BEFORE_TASK_INSTANCE_START) {
			beforeTaskInstanceStart(engine, task);
		} else if (event.getEventType()==TaskEvent.AFTER_TASK_INSTANCE_COMPLETE) {
			afterTaskInstanceCompleted(engine, task);
		} else if (event.getEventType()==TaskEvent.AFTER_WORKITEM_CREATED) {
			afterWorkItemCreated(engine,task, workitem);
		} else if (event.getEventType()==TaskEvent.AFTER_WORKITEM_COMPLETE) {
			afterWorkItemComplete(engine, task, workitem);
		}

	}
	
	protected void  beforeTaskInstanceStart(WorkflowEngine engine, ITaskInstance taskInstance) throws WorkflowException {
	    System.out.println(">>>>> before task start.");
	}
	
	protected void  afterTaskInstanceCompleted(WorkflowEngine currentSession, ITaskInstance taskInstance) throws WorkflowException {
	    
	    System.out.println(">>>>> after task complete.");
	}
	
    protected void afterWorkItemCreated(WorkflowEngine currentSession, ITaskInstance taskInstance, IWorkItem workItem) throws WorkflowException {
        
        System.out.println(">>>>> after workitem created.");
    }
    
    protected void afterWorkItemComplete(WorkflowEngine currentSession, ITaskInstance taskInstance, IWorkItem workItem) throws WorkflowException {
        
        System.out.println(">>>>> after workitem completed.");
    }    
}
